/*-------------------------------------
		sPlugin
	    By Scooby, 2010
-------------------------------------*/

local PLUGIN = {}

PLUGIN.Name = "Blind"
PLUGIN.Author = "Scooby"
PLUGIN.Command = "blind"
PLUGIN.Group = 2
PLUGIN.Category = "Fun"
PLUGIN.Format = "blind"
PLUGIN.Use = "<Player> <Amount>"
PLUGIN.Menu = {
	{
		title = "Choose Player",
		cont = "#players",
		apos = 1
	}
}


function PLUGIN:Main( ply, args )
	
	local pl = spl:FindPly( args[1] or ply:Nick() )
	local amt = tonumber( args[2] ) or 100
	
	if( amt < 0 ) then
		spl:PrintC( ply, spl.red, "Amount Cant Be Negative" )
		return false
	end
	
	amt = math.Clamp( amt, 0, 100 )
	
	local per = ( amt / 100 ) * 255
	print( tostring( per ) )
	
	if( #pl == 0 ) then
		spl:PrintC( ply, spl.red, spl.fnp )
		return false
	elseif( #pl > 1 ) then
		spl:PrintC( ply, spl.red, spl.fmp )
		return false
	end
	
	if( amt != 0 ) then
		umsg.Start( "Admin_Blind", pl[1] )
			umsg.Short( per )
		umsg.End()
		spl:PrintC( spl.blue, ply:Nick(), spl.white, " Blinded ", spl.red, pl[1]:Nick(), spl.white, " By ", spl.green, tostring( amt ), spl.white, " Percent" )
	else
		umsg.Start( "Admin_Blind", pl[1] )
			umsg.Short( per )
		umsg.End()
		spl:PrintC( spl.blue, ply:Nick(), spl.white, " Un-Blinded ", spl.red, pl[1]:Nick() )
	end
		
	
	
end

if( CLIENT ) then

usermessage.Hook( "Admin_Blind", function( um )
	local per = um:ReadShort()
	hook.Remove( "HUDPaint", "ADMIN_BLIND" )
	hook.Add( "HUDPaint", "ADMIN_BLIND", function()
		surface.SetDrawColor( Color( 255, 255, 255, per ) )
		surface.DrawRect( 0, 0, ScrW(), ScrH() )
	end)
end)

end

spl:AddPlugin( PLUGIN )